/**
 * 向后台获取course基本信息
 * @param course
 */
function getCourseSynopsis() {
    axios.post('/course/Synopsis/'+course.id+'/'+course.name)
        .then(function (res) {
            let course = res.data;
            document.getElementById('container').getElementsByClassName('dxinfo')[0].getElementsByTagName('h1')[0].innerHTML=course.name;
            document.getElementById('container').getElementsByClassName('dxinfo')[0].getElementsByTagName('p')[0].innerHTML=course.synopsis;
            getCourseTeacherList(course);
            return course;
        })
        .catch(function (error) {
           console.log(error);
        })
    /**
     * 获取该课程的老师的集合及其图像
     *
     */
    function getCourseTeacherList() {
        axios.post('/course/GetTeacherList/'+course.id+'/'+course.name)
            .then(function (data) {
                let teacherList = data.data;
                let count=0;
                let teacherListDoc = document.getElementById('teacherList').getElementsByTagName('li');
                for(let teacher in teacherList){
                    if(count>=teacherListDoc.length){break;}
                    let t = teacherListDoc[count];
                    t.getElementsByTagName('img')[0].src=teacher;
                    t.getElementsByTagName('a')[0].innerHTML=teacherList[teacher].name;
                    t.getElementsByTagName('a')[0].href='/'+TEACHER_INTRODUCED_HTML+'?/'+teacherList[teacher].id+'/'+teacherList[teacher].name;
                    count++;
                }
                add_page(teacherList,1,teacherListDoc);
            }).catch(function (error) {
            console.log(error);
        })
        /**
         * 老师分页
         * @param teacherList
         * @param pageSize
         * @param doc
         */
        function add_page(teacherList,pageSize,doc) {
            document.getElementById('teacherSum').innerHTML='共'+Object.keys(teacherList).length+'位老师';
            const display = document.getElementById('next_page').style.display;
            document.getElementById('up_page').onclick=function () {
                document.getElementById('next_page').style.display=display;
                pageSize--;
                setMsg(teacherList,doc);
                if(pageSize===1){document.getElementById('up_page').style.display='none';}
            }
            document.getElementById('next_page').onclick=function () {
                document.getElementById('up_page').style.display=display;
                pageSize++;
                setMsg(teacherList,doc);
                if(pageSize*doc.length===Object.keys(teacherList).length){document.getElementById('next_page').style.display='none'; }
            }
            function setMsg(teacherList,doc) {
                document.getElementById('teacher_page').innerHTML='第'+pageSize+'页';
                let num=0;
                let begin = (pageSize-1)*doc.length;
                let end = pageSize*doc.length;
                let count=0;
                for(let teacher in teacherList){
                    num++;
                    if(num<=begin){continue;}
                    if(num>end){break;}
                    let t = doc[count++];
                    t.getElementsByTagName('img')[0].src=teacher;
                    t.getElementsByTagName('a')[0].innerHTML=teacherList[teacher].name;
                    t.getElementsByTagName('a')[0].href='/'+TEACHER_INTRODUCED_HTML+'?/'+teacherList[teacher].id+'/'+teacherList[teacher].name;

                }
            }
        }
    }

}

//*******************************************************************
//++++++++++++++++++++++++++++++++++++++++++++
/**
 * 侧边栏单击事件
 *      课程介绍
 *      课程学习
 * @constructor
 */
function OnClick_sidebar() {
    /**
     * 显示隐藏侧边栏
     * @param ths
     */
    function show_a(ths) {
        if (ths.name === '') {
            for (let i = 0; i < menu_a.length; i++) {
                menu_a[i].classList.remove('on');
            }
            ths.className='on';
        } else {
            for (let i = 0; i < menu_a.length; i++) {
                if (ths.name === menu_a[i].name) {
                    ths.className = 'on';
                } else {
                    menu_a[i].classList.remove('on');
                }
            }
        }
    }
    /**
     * 显示隐藏主要内容
     */
    function show_right735() {
                if(arguments.length===0||arguments[0]===''){return;}
        let right735 = document.getElementById('kcms').getElementsByClassName('right735');
                for(let i=0;i<right735.length;i++){
                   right735[i].style.display='none';
                }
            for(let i=0;i<arguments.length;i++){
                document.getElementById(arguments[i]).style.display=original_display_right735;
            }
        }
    for(let i=0;i<menu_a.length;i++){
        menu_a[i].addEventListener('click',function () {
            show_a(this);
            let name = this.name;
            if(name==='course_overview'){
                show_right735(name,'course_dir');
            }else {
                show_right735(name);
            }
            if(name==='course_overview'){getCourse_overviewAndCourse_directory();}
            if(name==='course_study'){
               getCourse_video();}
        })
    }
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
 * “课程介绍”
 * 获取课程概述和课程目录
 */
function getCourse_overviewAndCourse_directory() {
    hidden_elementsRight735(document.getElementById('kcms').getElementsByClassName('right735'));
    getCourse_overview();
    getDivTree();

    //获取课程概述
    function getCourse_overview() {
        axios.post('/course/Overview/'+course.id+'/'+course.name)
            .then(function (OverviewData) {
                let split=OverviewData.data.overview.split('\n')
                let div = document.getElementById('course_overview').getElementsByClassName('content_news')[0];
                div.innerHTML='';
                for(let i=0;i<split.length;i++){
                    if(split[i].replaceAll(' ','')===''){continue;}
                    let text = split[i];
                    let p = document.createElement('p');
                    p.innerHTML=text;
                    div.append(p);
                }
            }).catch(function (error) {
            console.log('课程介绍:'+error);
        })
    }

    /**
     * 隐藏right735前两个以外的元素
     * @param div
     */
    function hidden_elementsRight735(div) {
        for(let i=0;i<div.length;i++){
            let element = div[i];
            if(element.id!=='course_dir'&&element.id!=='course_overview'){
                element.style.display='none';}else {
                element.style.display=original_display_right735;
            }}
    }

    /**
     * 获取课程目录生成目录树
     */
    function getDivTree() {

        var names = {}; // hash to keep track of what names have been used
        function init() {
            // When a Node is selected, highlight the corresponding HTML element.
            function nodeSelectionChanged(node) {
                if (node.isSelected) {
                    names[node.data.name].style.backgroundColor = "lightblue";
                } else {
                    names[node.data.name].style.backgroundColor = "";
                }
            }
            // if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this
            var $ = go.GraphObject.make;  // for conciseness in defining templates

           let myDiagram =
                $(go.Diagram, "myDiagramDiv",
                    {
                        initialAutoScale: go.Diagram.UniformToFill,
                        // define the layout for the diagram
                        layout: $(go.TreeLayout, { nodeSpacing: 5, layerSpacing: 30 })
                    });

            // Define a simple node template consisting of text followed by an expand/collapse button
            myDiagram.nodeTemplate =
                $(go.Node, "Horizontal",
                    { selectionChanged: nodeSelectionChanged },  // this event handler is defined below
                    $(go.Panel, "Auto",
                        $(go.Shape, { fill: "#1F4963", stroke: null }),
                        $(go.TextBlock,
                            {
                                font: "bold 13px Helvetica, bold Arial, sans-serif",
                                stroke: "white", margin: 3
                            },
                            new go.Binding("text", "key"))
                    ),
                    $("TreeExpanderButton")
                );

            // Define a trivial link template with no arrowhead.
            myDiagram.linkTemplate =
                $(go.Link,
                    { selectable: false },
                    $(go.Shape));  // the link shape

            // create the model for the DOM tree
            myDiagram.model =
                $(go.TreeModel, {
                    isReadOnly: true,  // don't allow the user to delete or copy nodes
                    // build up the tree in an Array of node data
                    nodeDataArray: traverseDom()
                });

        }
        // Walk the DOM, starting at document, and return an Array of node data objects representing the DOM tree
        // Typical usage: traverseDom(document.activeElement)
        // The second and third arguments are internal, used when recursing through the DOM
        function traverseDom() {
            let dataArray=[];
            dataArray=[
                {
                    "key": "BODY",
                    "name": "BODY",
                    "__gohashid": 459
                },
                {
                    "key": "SCRIPT",
                    "name": "SCRIPT",
                    "parent": "BODY",
                    "__gohashid": 460
                },
                {
                    "key": "P",
                    "name": "P",
                    "parent": "BODY",
                    "__gohashid": 461
                },
                {
                    "key": "A",
                    "name": "A",
                    "parent": "P",
                    "__gohashid": 462
                },
                {
                    "key": "A1",
                    "name": "A1",
                    "parent": "P",
                    "__gohashid": 463
                },
                {
                    "key": "DIV (allSampleContent)",
                    "name": "DIV (allSampleContent)",
                    "parent": "BODY",
                    "__gohashid": 464
                },
                {
                    "key": "SCRIPT (code)",
                    "name": "SCRIPT (code)",
                    "parent": "DIV (allSampleContent)",
                    "__gohashid": 465
                },
                {
                    "key": "DIV (sample)",
                    "name": "DIV (sample)",
                    "parent": "DIV (allSampleContent)",
                    "__gohashid": 466
                },
                {
                    "key": "DIV (myDiagramDiv)",
                    "name": "DIV (myDiagramDiv)",
                    "parent": "DIV (sample)",
                    "__gohashid": 467
                },
                {
                    "key": "CANVAS",
                    "name": "CANVAS",
                    "parent": "DIV (myDiagramDiv)",
                    "__gohashid": 468
                },
                {
                    "key": "DIV",
                    "name": "DIV",
                    "parent": "DIV (myDiagramDiv)",
                    "__gohashid": 469
                },
                {
                    "key": "DIV1",
                    "name": "DIV1",
                    "parent": "DIV",
                    "__gohashid": 470
                },
                {
                    "key": "P1",
                    "name": "P1",
                    "parent": "DIV (sample)",
                    "__gohashid": 471
                },
                {
                    "key": "P2",
                    "name": "P2",
                    "parent": "DIV (sample)",
                    "__gohashid": 472
                },
                {
                    "key": "A2",
                    "name": "A2",
                    "parent": "P2",
                    "__gohashid": 473
                },
                {
                    "key": "A3",
                    "name": "A3",
                    "parent": "P2",
                    "__gohashid": 474
                },
                {
                    "key": "P (lastParagraph)",
                    "name": "P (lastParagraph)",
                    "parent": "DIV (sample)",
                    "__gohashid": 475
                },
                {
                    "key": "DIV (otherInfo)",
                    "name": "DIV (otherInfo)",
                    "parent": "DIV (sample)",
                    "__gohashid": 476
                },
                {
                    "key": "DIV (tableContainer)",
                    "name": "DIV (tableContainer)",
                    "parent": "DIV (otherInfo)",
                    "__gohashid": 477
                },
                {
                    "key": "TABLE",
                    "name": "TABLE",
                    "parent": "DIV (tableContainer)",
                    "__gohashid": 478
                },
                {
                    "key": "TBODY",
                    "name": "TBODY",
                    "parent": "TABLE",
                    "__gohashid": 479
                },
                {
                    "key": "TR",
                    "name": "TR",
                    "parent": "TBODY",
                    "__gohashid": 480
                },
                {
                    "key": "TH (firstHeader)",
                    "name": "TH (firstHeader)",
                    "parent": "TR",
                    "__gohashid": 481
                },
                {
                    "key": "TH (secondHeader)",
                    "name": "TH (secondHeader)",
                    "parent": "TR",
                    "__gohashid": 482
                },
                {
                    "key": "TR1",
                    "name": "TR1",
                    "parent": "TBODY",
                    "__gohashid": 483
                },
                {
                    "key": "TD",
                    "name": "TD",
                    "parent": "TR1",
                    "__gohashid": 484
                },
                {
                    "key": "TD1",
                    "name": "TD1",
                    "parent": "TR1",
                    "__gohashid": 485
                },
                {
                    "key": "TR2",
                    "name": "TR2",
                    "parent": "TBODY",
                    "__gohashid": 486
                },
                {
                    "key": "TD2",
                    "name": "TD2",
                    "parent": "TR2",
                    "__gohashid": 487
                },
                {
                    "key": "TD3",
                    "name": "TD3",
                    "parent": "TR2",
                    "__gohashid": 488
                },
                {
                    "key": "DIV (listContainer)",
                    "name": "DIV (listContainer)",
                    "parent": "DIV (otherInfo)",
                    "__gohashid": 489
                },
                {
                    "key": "P3",
                    "name": "P3",
                    "parent": "DIV (listContainer)",
                    "__gohashid": 490
                },
                {
                    "key": "UL (groceryList)",
                    "name": "UL (groceryList)",
                    "parent": "DIV (listContainer)",
                    "__gohashid": 491
                },
                {
                    "key": "LI",
                    "name": "LI",
                    "parent": "UL (groceryList)",
                    "__gohashid": 492
                },
                {
                    "key": "LI1",
                    "name": "LI1",
                    "parent": "UL (groceryList)",
                    "__gohashid": 493
                },
                {
                    "key": "LI2",
                    "name": "LI2",
                    "parent": "UL (groceryList)",
                    "__gohashid": 494
                },
                {
                    "key": "P4",
                    "name": "P4",
                    "parent": "DIV (otherInfo)",
                    "__gohashid": 495
                },
                {
                    "key": "A4",
                    "name": "A4",
                    "parent": "P4",
                    "__gohashid": 496
                },
                {
                    "key": "A5",
                    "name": "A5",
                    "parent": "P4",
                    "__gohashid": 497
                },
                {
                    "key": "A6",
                    "name": "A6",
                    "parent": "P4",
                    "__gohashid": 498
                },
                {
                    "key": "P5",
                    "name": "P5",
                    "parent": "DIV (sample)",
                    "__gohashid": 499
                },
                {
                    "key": "P6",
                    "name": "P6",
                    "parent": "DIV (allSampleContent)",
                    "__gohashid": 500
                },
                {
                    "key": "A7",
                    "name": "A7",
                    "parent": "P6",
                    "__gohashid": 501
                },
                {
                    "key": "SCRIPT1",
                    "name": "SCRIPT1",
                    "parent": "BODY",
                    "__gohashid": 502
                }
            ];
            return dataArray;
        }
        window.addEventListener('DOMContentLoaded', init);
        getCourse_videoCatalogue();

        function getCourse_videoCatalogue() {
            getMaxGrade();
            /**
             * 获取该课程的最大级别
             */
            function getMaxGrade() {
                axios.post('/course/video/getMaxGrade/'+course.id)
                    .then(function (gradeData) {
                        let grade = gradeData.data;
                        grade=[
                            1,
                           0,
                            0,
                            125,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0
                        ];
                        let zero=grade.length-1;
                        for(let  i=grade.length-1;i>=1;i--){
                            if(grade[i]===0){
                                zero=i;
                            }else {break;}
                        }
                        for(let i=1;i<zero;i++){
                            if(grade[i]===0){continue;}
                            getCourse_videoCatalogueByGrade(i+1);
                        }

                    }).catch(function (error) {
                    console.log(error);
                })
                /**
                 * 获取指定级别的目录
                 */
                function getCourse_videoCatalogueByGrade(grade) {
                    axios.post('/course/video/getCourse_videoCatalogue/'+course.id+'/'+grade)
                        .then(function (catalogueData) {

                        }).catch(function (error) {console.log(error);})
                }

            }

        }

          }
}
/**
 * 课程学习
 */
function getCourse_video() {
    let myVideos = document.getElementById('course_study').getElementsByClassName('myvideo');
  /**
     * 添加课程视频到元素中
     * @param value
     * @param myVideos
     */
    function setCourse_videoInDocument(videoList) {
       for(let i=0;i<myVideos.length;i++){myVideos[i].style.display=original_display_myvideo;}
         for (let i = 0; i < Math.min(myVideos.length, videoList.length); i++) {
            let myVideo = myVideos[i];
            let course_video = videoList[i];
            myVideo.getElementsByTagName('span')[0].innerHTML = course_video.id;
            myVideo.getElementsByTagName('h3')[0].getElementsByTagName('a')[0].innerHTML = course_video.name;
            myVideo.getElementsByTagName('h3')[0].getElementsByTagName('a')[0].href = '/' + course_video_play + '?/' + course_video.course_id + '/' + course_video.id + '/' + course_video.name;
            myVideo.getElementsByTagName('span')[1].getElementsByTagName('a')[0].href = '/' + course_video_play + '?/' + course_video.course_id + '/' + course_video.id + '/' + course_video.name;
            myVideo.getElementsByTagName('span')[1].getElementsByTagName('a')[0].title = course_video.name;
            findCourse_videoTeacherList(course_video, myVideo);
             findCourse_videoPict(course_video,myVideo);
        }
        // alert(2);
        if(videoList.length<myVideos.length){
            for(let i=videoList.length;i<myVideos.length;i++){
                myVideos[i].style.display='none';
            }
        }
        /**
         * 获取课程视频的主讲老师的list
         * @param course_video
         * @param myVideo
         */
        function findCourse_videoTeacherList(course_video, myVideo) {
            axios.post('/course/video/getTeacherList/' + course_video.course_id + '/' + course_video.id)
                .then(function (teacherListData) {
                    let teacherList = teacherListData.data;
                    let tea = '<b>主讲</b>';
                    for (let i = 0; i < Math.min(teacherList.length, 2); i++) {
                        let teacher = teacherList[i];
                        tea += '<a href="/' + TEACHER_INTRODUCED_HTML + '?/' + teacher.id + '/' + teacher.name + '">' + teacher.name + '</a>, ';
                    }
                    if (2 < teacherList.length) {
                        tea += '<a href="#" title="还有其他' + (teacherList.length - 2) + '老师">...</a>';
                    }
                    myVideo.getElementsByClassName('title6')[0].innerHTML = tea;

                }).catch(function (error) {
                console.log(error);
            })
        }
        // alert(3);
      //获取课程视频封面
      function findCourse_videoPict(course_video, myVideo) {
          axios.post('/course/video/findCourse_videoPict/' + course_video.course_id + '/' + course_video.id)
              .then(function (Course_videoPictData) {
                // alert(Course_videoPictData.data);
                  myVideo.getElementsByTagName('img')[0].src=Course_videoPictData.data;
              }).catch(function (error) {console.log(error);})
      }
    }
    axios.post('/course/video/'+course.id+'/'+course.name+'/'+myVideos.length)
        .then(function (videoListData) {
            let videoList=videoListData.data;
            setCourse_videoInDocument(videoList);
           setPage(videoList);
           // alert('222')
         }).catch(function (error) {console.log('课程视频'+error);})
    /**
     * 设置分页
     */
    function setPage(videoList) {
        /**
         * 删除或者添加页码
         */
        function del_add_PageA(pageCount) {
            if(a_page.length>pageCount){
                 for(let i=pageCount;i<a_page.length;i++){
                    a_page[i].style.display='none';
                }
            }
        }
        if(videoList.length<myVideos.length){
            //不用分页
            document.getElementById('course_vide_page').remove();return;
        }
        let a_page = document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByTagName('a');
        let em = document.getElementById('course_vide_page').getElementsByTagName('em')[0];
         axios.post('/course/video/FindPageCount/'+course.id+'/'+course.name+'/'+myVideos.length)
            .then(function (pageData) {
                const pageCount=pageData.data;
                em.innerHTML=pageCount+'/'+document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByClassName('on')[0].innerHTML;
                if(pageCount===1){document.getElementById('course_vide_page').remove();return;}
                del_add_PageA(pageCount);
                new OnClick_Page(pageCount);
                   prev_next(pageCount);
                goToPage(pageCount);
            });
        /**
         * 向后台请求指定页码的数据
         * @param page
         */
        function setHtmlFormPage(page) {
            axios.post('/course/video/getCourse_videoByPage/' + course.id + '/' + page + '/' + myVideos.length)
                .then(function (videoListData) {
                    setCourse_videoInDocument(videoListData.data);
                }).catch(function (error) {console.log(error);})
        }
        /**
         * 页码单击事件
         * @constructor
         */
        function OnClick_Page(pageCount) {
            for(let i=0;i<a_page.length;i++){
                a_page[i].onclick=function () {
                    document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByClassName('on')[0].classList.remove('on');
                    this.className='on';
                    em.innerHTML=pageCount+'/'+parseInt(this.innerHTML);
                 setHtmlFormPage( parseInt(this.innerHTML));
                }
            }
        }
        /**
         * 上一页 下一页事件
         * @param pageCount
         * @param lastPage
         */
        function prev_next(pageCount) {
              let next = document.getElementById('course_vide_page').getElementsByClassName('next')[0].getElementsByTagName('a')[0];
            let prev = document.getElementById('course_vide_page').getElementsByClassName('prev')[0].getElementsByTagName('a')[0];
             document.getElementById('course_vide_page').getElementsByClassName('prev')[0].style.display='none';
            next.onclick=function () {
                for(let i=0;i<a_page.length;i++){a_page[i].style.display=original_display_Page_A;}
                let lastPage;
                for(let i=a_page.length-1;i>=0;i--){
                    if(a_page[i].style.display===original_display_Page_A){
                        lastPage=parseInt(a_page[i].innerHTML);
                        break;
                    }
                }
                document.getElementById('course_vide_page').getElementsByClassName('prev')[0].style.display=original_display_Next;
                document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByClassName('on')[0].classList.remove('on');
                a_page[0].className='on';
                em.innerHTML=pageCount+'/'+(lastPage+1);
                let begin=0;
                for(let i=lastPage+1;i<=Math.min(pageCount,lastPage+a_page.length);i++){
                    a_page[begin++].innerHTML=i+'';
                }
                if(pageCount<(lastPage+a_page.length)){
                    for(let i=begin;i<a_page.length;i++){a_page[i].style.display='none';}
                    lastPage=pageCount;
                }else {
                    lastPage=parseInt(a_page[a_page.length-1].innerHTML);
                }
                if(lastPage===pageCount){
                    document.getElementById('course_vide_page').getElementsByClassName('next')[0].style.display='none';
                }
             setHtmlFormPage(parseInt(a_page[0].innerHTML));
            }

            prev.onclick=function () {
                let lastPage;
                for(let i=a_page.length-1;i>=0;i--){
                    if(a_page[i].style.display===original_display_Page_A){
                        lastPage=parseInt(a_page[i].innerHTML);
                        break;
                    }
                }
                // alert(lastPage);
                for(let i=0;i<a_page.length;i++){a_page[i].style.display=original_display_Page_A;}
                document.getElementById('course_vide_page').getElementsByClassName('next')[0].style.display=original_display_Next;
               document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByClassName('on')[0].classList.remove('on');
               a_page[a_page.length-1].className='on';
               let firstPage=0;
               for(let i=0;i<a_page.length;i++){
                   if(parseInt(a_page[i].innerHTML)===lastPage){
                       firstPage=lastPage-i-1;
                       break;
                   }
               }
                // alert(firstPage);
                lastPage=firstPage;
               em.innerHTML=pageCount+'/'+firstPage;
               for(let i=a_page.length-1;i>=0;i--){
                   if(firstPage<=0){
                       a_page[i].style.display='none';
                   }else {
                       a_page[i].innerHTML = (firstPage--) + '';
                   }
               }

               // alert(lastPage+"#"+firstPage);
               if((lastPage-a_page.length)<=0){
                   document.getElementById('course_vide_page').getElementsByClassName('prev')[0].style.display='none';
               }
              setHtmlFormPage(lastPage);
            }
        }
        /**
         * 跳转到指定页码
         * @param pageCount
         */
        function goToPage(pageCount) {
              const sub = document.getElementById('course_vide_page').querySelector('input.btngo');
            const val = document.getElementById('course_vide_page').querySelector('input.inputpage');
            sub.onclick=function () {
               if(val.value===''){alert('请输入页码');return;}
                const page = parseInt(val.value);
                if(page>pageCount){alert(page+'超过总页数'+pageCount+ ' , 请出现输入');val.value='';return;}
                let next = document.getElementById('course_vide_page').getElementsByClassName('next')[0];
                let prev = document.getElementById('course_vide_page').getElementsByClassName('prev')[0];
                next.style.display=original_display_Next;prev.style.display=original_display_Next;
                em.innerHTML=pageCount+'/'+page;
                document.getElementById('course_vide_page').getElementsByClassName('num')[0].getElementsByClassName('on')[0].classList.remove('on');
                for(let i=0;i<a_page.length;i++){a_page[i].style.display=original_display_Page_A;}
                if(pageCount<=a_page.length){
                    for(let i=0;i<a_page.length;i++){
                        a_page[i].innerHTML=(i+1)+'';
                        if(parseInt(a_page[i].innerHTML)===page){a_page[i].className='on';}
                    }
                    prev.style.display='none';
                }
                if(pageCount>a_page.length){
                    // console.log(pageCount+'#'+a_page.length);
                    const mid = a_page.length/2;  //5
                   if(page<=mid){
                       prev.style.display='none';
                       for(let i=0;i<a_page.length;i++){
                           a_page[i].innerHTML=(i+1)+'';
                           if(parseInt(a_page[i].innerHTML)===page){a_page[i].className='on';}
                       }
                   }
                   if(page>mid){
                       let temp=page;
                       for(let i=mid;i>=0;i--){
                           a_page[i].innerHTML=(temp--)+'';
                           if(parseInt(a_page[i].innerHTML)===page){
                               // console.log('循环中了 '+page+'#'+a_page[i].innerHTML);
                               a_page[i].className='on';}
                     }
                       // console.log(page+'#'+temp);
                       // console.log(page+'#'+a_page.length+'#'+(page+(a_page.length-mid)-1)+'#'+mid+'#'+pageCount);
                       if((page+(a_page.length-mid)-1)>pageCount){
                           let temp=page+1;
                           // console.log(temp);
                           for(let i=mid+1;i<a_page.length;i++){
                               if(temp>pageCount){
                                   a_page[i].style.display='none';
                               }
                               a_page[i].innerHTML=temp+'';
                               temp++;
                           }
                           next.style.display='none';
                       }else {
                           let temp=page+1;
                           for(let i=mid+1;i<a_page.length;i++){
                               a_page[i].innerHTML=(temp++)+'';
                           }
                       }

                      }
                }
                setHtmlFormPage(page);
            }
        }
    }

}




